package com.vstudy.zx.utils;

import java.io.*;

public class IOUtil {
    // 将文章写入文件
    public static void writeArticle(String username, String charset, String content) throws IOException {
        OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(username), charset);
        out.write(content);
        out.close();
    }

    public static String readArticle(String realPath, String charset) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(realPath), charset));
        StringBuffer sb = new StringBuffer();
        String tmp = null;
        while ((tmp = reader.readLine()) != null) {
            sb.append(tmp);
        }
        reader.close();
        return sb.toString();
    }

    public static boolean deleteFile(String realPath) {
        File file = new File(realPath);
        if (file.exists()) {
            boolean delete = file.delete();
            return delete;
        }
        return false;
    }
}
